<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login and Register</title>
<style>
  body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
  }
  
  .login-container {
    max-width: 400px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    overflow: hidden;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
  }
  
  .form-container {
    padding: 20px;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  .form-container.register {
    transform: translateX(-100%);
  }
  
  .form-title {
    margin-bottom: 10px;
    font-size: 1.5rem;
  }
  
  label {
    margin-bottom: 5px;
  }
  
  input[type="text"], input[type="password"] {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
  }
  
  button {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }
  
  button:hover {
    background-color: #0056b3;
  }
  
  .switch-mode {
    text-align: center;
    margin-top: 10px;
    cursor: pointer;
    color: #007bff;
  }
  
  .switch-mode:hover {
    text-decoration: underline;
  }
</style>
</head>
<body>
<div class="login-container">
  <div class="form-container">
    <div class="form-title">登录</div>
    <form id="loginForm">
      <label for="username">用户名：</label>
      <input type="text" id="username" name="username" required>
      <label for="password">密码：</label>
      <input type="password" id="password" name="password" required>
      <button type="submit">登录</button>
    </form>
    <div class="switch-mode" id="toggleForm">没有账号？点击注册</div>
  </div>
  
  <div class="form-container register">
    <div class="form-title">注册</div>
    <form id="registerForm">
      <label for="newUsername">用户名：</label>
      <input type="text" id="newUsername" name="newUsername" required>
      <label for="newPassword">密码：</label>
      <input type="password" id="newPassword" name="newPassword" required>
      <button type="submit">注册</button>
    </form>
    <div class="switch-mode" id="toggleForm">已有账号？点击登录</div>
  </div>
</div>

<script>
document.getElementById('toggleForm').addEventListener('click', function() {
  const loginForm = document.querySelector('.login-container .form-container');
  const registerForm = document.querySelector('.login-container .form-container.register');
  
  // 判断当前哪个表单处于 register 状态，然后进行切换
  if (loginForm.classList.contains('register')) {
    loginForm.classList.remove('register');
    registerForm.classList.add('register');
  } else {
    registerForm.classList.remove('register');
    loginForm.classList.add('register');
  }
});
</script>

</body>
</html>
